---
title: 'prevAll | Cypress Documentation'
description: Get all previous siblings of each DOM element in a set of matched DOM elements in Cypress.
sidebar_label: prevAll
slug: /api/commands/prevall
---

<ProductHeading product="app" />

# prevAll

Get all previous siblings of each DOM element in a set of matched DOM elements.

:::info

The querying behavior of this command matches exactly how
[`.prevAll()`](http://api.jquery.com/prevAll) works in jQuery.

:::

## Syntax

```javascript
.prevAll()
.prevAll(selector)
.prevAll(options)
.prevAll(selector, options)
```

### Usage

<Icon name="check-circle" color="green" /> **Correct Usage**

```javascript
cy.get('.active').prevAll() // Yield all links previous to `.active`
```

<Icon name="exclamation-triangle" color="red" /> **Incorrect Usage**

```javascript
cy.prevAll() // Errors, cannot be chained off 'cy'
cy.getCookies().prevAll() // Errors, 'getCookies' does not yield DOM element
```

### Arguments

<Icon name="angle-right" /> **selector _(String selector)_**

A selector used to filter matching DOM elements.

<Icon name="angle-right" /> **options _(Object)_**

Pass in an options object to change the default behavior of `.prevAll()`.

| Option    | Default                                                           | Description                                                                         |
| --------- | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| `log`     | `true`                                                            | Displays the command in the [Command log](/app/core-concepts/open-mode#Command-Log) |
| `timeout` | [`defaultCommandTimeout`](/app/references/configuration#Timeouts) | Time to wait for `.prevAll()` to resolve before [timing out](#Timeouts)             |

<HeaderYields />

- `.prevAll()` yields the new DOM element(s) it found.
- `.prevAll()` is a query, and it is _safe_ to chain further commands.

## Examples

### No Args

#### Find all of the element's siblings before `.third`

```html
<ul>
  <li>apples</li>
  <li>oranges</li>
  <li class="third">bananas</li>
  <li>pineapples</li>
  <li>grapes</li>
</ul>
```

```javascript
// yields [<li>apples</li>, <li>oranges</li>]
cy.get('.third').prevAll()
```

### Selector

#### Find all of the previous siblings of each `li`. Keep only the ones with a class `selected`

```html
<ul>
  <li>apples</li>
  <li>oranges</li>
  <li>bananas</li>
  <li class="selected">pineapples</li>
  <li>grapes</li>
</ul>
```

```javascript
// yields <li>pineapples</li>
cy.get('li').prevAll('.selected')
```

## Rules

<HeaderRequirements />

- `.prevAll()` requires being chained off a command that yields DOM element(s).

<HeaderAssertions />

- `.prevAll()` will automatically [retry](/app/core-concepts/retry-ability)
  until the element(s)
  [exist in the DOM](/app/core-concepts/introduction-to-cypress#Implicit-Assertions).
- `.prevAll()` will automatically [retry](/app/core-concepts/retry-ability)
  until all chained assertions have passed.

<HeaderTimeouts />

- `.prevAll()` can time out waiting for the element(s) to
  [exist in the DOM](/app/core-concepts/introduction-to-cypress#Implicit-Assertions).
- `.prevAll()` can time out waiting for assertions you've added to pass.

## Command Log

**_Find all elements before the `.active` li_**

```javascript
cy.get('.left-nav').find('li.active').prevAll()
```

The commands above will display in the Command Log as:

<DocsImage
  src="/img/api/prevall/find-all-previous-elements-with-optional-selector.png"
  alt="Command Log prevAll"
/>

When clicking on `prevAll` within the command log, the console outputs the
following:

<DocsImage
  src="/img/api/prevall/console-log-all-previous-elements-traversed.png"
  alt="Console Log prevAll"
/>

## See also

- [`.nextAll()`](/api/commands/nextall)
- [`.parents()`](/api/commands/parents)
- [`.prev()`](/api/commands/prev)
- [`.prevUntil()`](/api/commands/prevuntil)
